//
// Copyright (c) 2009 All Right Reserved
//
// vl
//
// 2009-01-01
// Contains ...
using System;
using System.Diagnostics.Contracts;
using System.Xml.Linq;
using JetBrains.Annotations;
namespace LargoCommon.Music
{
///
/// Musical Block Model.
///
[Serializable]
public class AbstractModel
{
#region Fields
///
/// Source Musical Block.
///
private MusicalBlock sourceMusicalBlock;
///
/// Block Changes.
///
[NonSerialized]
private MusicalChanges blockChanges;
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
public AbstractModel()
{
this.BlockChanges = new MusicalChanges();
this.Header = new MusicalHeader();
}
///
/// Initializes a new instance of the class.
///
/// The mark block model.
public AbstractModel(XElement markBlockModel)
{
Contract.Requires(markBlockModel != null);
if (markBlockModel == null) {
return;
}
this.Name = (string)markBlockModel.Attribute("Name");
var xheader = markBlockModel.Element("Header");
this.Header = new MusicalHeader(xheader);
this.BlockChanges = new MusicalChanges(markBlockModel);
}
#endregion
#region Properties - Xml
/// Gets Xml representation.
/// Property description.
public XElement GetXElement
{
get
{
XElement xmblockModel = new XElement(
"Model",
new XAttribute("Name", this.Name ?? "New model"),
new XAttribute("NumberOfBars", this.Header.NumberOfBars),
new XAttribute("Tempo", this.Header.Tempo));
xmblockModel.Add(this.Header.System.GetXElement);
XElement xchanges = this.BlockChanges.GetXElement;
xmblockModel.Add(xchanges);
return xmblockModel;
}
}
#endregion
#region Public Properties
///
/// Gets or sets the header.
///
///
/// The header.
///
public MusicalHeader Header { get; set; }
///
/// Gets or sets Source Musical Block.
///
/// Property description.
public MusicalBlock SourceMusicalBlock
{
get
{
Contract.Ensures(Contract.Result() != null);
if (this.sourceMusicalBlock == null) {
throw new InvalidOperationException("Source musical block is null.");
}
return this.sourceMusicalBlock;
}
set => this.sourceMusicalBlock = value ?? throw new ArgumentException("Source musical block cannot be set null.", nameof(value));
}
///
/// Gets or sets the musical block changes.
///
/// Property description.
public MusicalChanges BlockChanges
{
get
{
Contract.Ensures(Contract.Result() != null);
if (this.blockChanges == null) {
throw new InvalidOperationException("Block changes are null.");
}
return this.blockChanges;
}
set => this.blockChanges = value ?? throw new ArgumentException("Block changes cannot be set null.", nameof(value));
}
#endregion
#region Naming public properties
///
/// Gets or sets Name.
///
/// Property description.
public string Name { get; set; }
///
/// Gets or sets the number.
///
///
/// The number.
///
public int Number { get; set; }
///
/// Gets or sets a value indicating whether Is Selected.
///
/// Property description.
public bool IsSelected { get; set; }
#endregion
#region Other public properties
///
/// Gets the order value.
///
/// Property description.
[UsedImplicitly]
public string OrderValue => MusicalProperties.GetOrderValue(this.Header.System.HarmonicOrder, this.Header.System.RhythmicOrder);
/// Gets total duration of the block.
/// Property description.
/// Returns value.
[UsedImplicitly]
public long TotalDuration
{
get
{
long num = this.Header.System.RhythmicOrder * this.Header.NumberOfBars;
return num;
}
}
#endregion
#region Public methods
///
/// Returns a that represents this instance.
///
///
/// A that represents this instance.
///
public override string ToString()
{
return this.Name;
}
#endregion
}
}